/**
 * 
 */
package com.qunar.crawler.utils;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * @author tao.zhang
 */
public class TourUrlFrontier {

    private TourUrlFrontier() {
    }

    // private static BlockingQueue<String> urlQueue = new ArrayBlockingQueue<String>(10000);

    private static ConcurrentLinkedQueue<String> urlQueue = new ConcurrentLinkedQueue<String>();

    private static TourUrlFrontier frontier = new TourUrlFrontier();

    public static TourUrlFrontier getInstance() {
        return frontier;
    }

    public String take() {
        return urlQueue.poll();

    }

    public boolean isEmpty() {
        return urlQueue.isEmpty();
    }

    public void put(List<String> tourUrls) {
        urlQueue.addAll(tourUrls);
    }

    public static void fill() {

        String tourUrlBase = "http://117go.com/live_p";
        String tourUrlEnd = ".html";
        
        List<String> tourUrls = new ArrayList<String>();

        tourUrls.add("http://117go.com/live.html");
        for (int i = 1; i <= 300; i++) {
            tourUrls.add(tourUrlBase + i + tourUrlEnd);
        }
        urlQueue.addAll(tourUrls);

    }
}
